package com.db.patterns.singleton.demo05;

import java.io.Serializable;

/**
 * 懒汉式 - 静态类部类
 */
public class Singleton implements Serializable {
    private Singleton() {

    }

    private static class SingletonHolder {
        private static final Singleton INSTANCE = new Singleton();
    }

    public static Singleton getInstance() {
        return SingletonHolder.INSTANCE;
    }

    // 防止虚拟化创建多个实例
    public Object readResolve() {
        return SingletonHolder.INSTANCE;
    }
}
